package cn.tedu.account;

import cn.tedu.account.entity.AccountMessage;
import cn.tedu.account.service.AccountService;
import cn.tedu.account.util.JsonUtil;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @description:
 * @author: LiuXingYu
 * @date: 2021/9/26 15:27
 */
@RocketMQMessageListener(topic = "orderTopic", consumerGroup = "account-group")
public class AccountConsumer implements RocketMQListener<String> {

    @Autowired
    private AccountService accountService;

    @Override
    public void onMessage(String s) {
        AccountMessage am = JsonUtil.from(s, AccountMessage.class);
        accountService.decrease(am.getUserId(), am.getMoney());
    }
}
